<?php

require_once '../application/controllers/Super_Controller.php';

class IndexController extends Super_Controller {

    public function init() {
        $this->view->p_title = 'Developer blog';
        $this->view->p_key = 'Всё о web-разработке и продвижении сайтов, прикладное программирование Delphi';
        $this->view->p_desc = 'php,php5,php6,zend framework, javascript,ajax,jquery,html5,css framework,cms,html,css,javascript,ajax,jquery,delphi';
    }

    public function indexAction() {
        $PGM = new Application_Model_Pages();
        $this->view->commentCnt = $PGM->getCntCommentPage();
        //_debug($this->view->pages,1
        $onPage = 10;
        $page = (int) $this->_request->page;
        if (empty($page))
            $page = 1;

        $PGM = new Application_Model_Pages();
        $order_by = '`rating` DESC';
        $addf = $addw = '';
        if (isset($_GET['search'])) {
            $base = "MATCH (title,content) AGAINST ('" . addslashes($_GET['search']) . "')";
            $addf = ', ' . $base . ' as relev';
            $addw = ' AND ' . $base;
            $order_by = 'relev DESC';
        }
        $result = $PGM->select_pn('pages', '`id`,`category_id`,`title`, `url`, `top_menu`, `preview`, `in_main`, `view`'.$addf,
                        "`active` = 1 AND `in_main` = 1 AND `preview` != '' ".$addw,
                        $order_by,
                        ($page - 1) * $onPage,
                        $onPage);
        // _debug($result);

        $this->view->info = $result['result'];
        $PGM->addTagsToPage($this->view->info);

        $this->view->countRow = $result['total'];

        $paginator = Zend_Paginator::factory((int) $this->view->countRow);
        $paginator->setDefaultItemCountPerPage($onPage);
        $paginator->setCurrentPageNumber($page);

        $this->view->paginator = $paginator;
        $this->view->onPage = $onPage;
    }

}

